using System;
using System.Xml.Linq;

namespace Savviety.ServiceManager.API.Criteria
{
    public class ContainedExpression : Expression
    {
        public ContainedExpression(string className)
        {
            Root = new XElement("Contained");
            var el = new XElement("Class", className);
            Root.Add(el);
            el = new XElement("Expression");
            Root.Add(el);
        }

        public void Add(SimpleExpression expression)
        {
            if(Expressions.Count==1)
                throw new ArgumentException("This expression only supports one Simple");
            Expressions.Add(expression);     
        }

        public override XElement ToXElement()
        {

            foreach (var expression in Expressions)
            {
                Root.Add(expression.ToXElement());
            }
            return Root;
           
        }

    }
}